//
//  CYRechargeHeaderView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/6.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYRechargeHeaderView.h"
@interface CYRechargeHeaderView()
@property (nonatomic, strong) CYImageView *portraitIMG;
@property (nonatomic, strong) CYLabel *userNameLBL;
@property (nonatomic, strong) CYLabel *moneyTitleLBL;
@property (nonatomic, strong) CYLabel *moneyLBL;
@property (nonatomic, strong) CYView *bottomLine;//
@end
@implementation CYRechargeHeaderView
- (instancetype)init{
    self = [super init];
    if (self) {
        self.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, AUTO(50));
        self.imageName = @"portrait";
        self.userName = @"彩票狗";
        self.money = 0.00000;
        self.bottomLine.hidden = NO;
    }
    return self;
}

/*头像*/
- (CYImageView *)portraitIMG{
    if (!_portraitIMG) {
        _portraitIMG = [[CYImageView alloc]initWithImageName:_imageName size:
                        CGSizeMake(self.bounds.size.height - AUTO(20),self.bounds.size.height -  AUTO(20)) isRadius:YES];
        [self addSubview:_portraitIMG];
        
        [_portraitIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(13);
            make.centerY.equalTo(self).with.offset(- 3);
            make.size.mas_equalTo(_portraitIMG.bounds.size);
        }];
    }
    return _portraitIMG;
}

/*名称*/
- (CYLabel *)userNameLBL{
    if (!_userNameLBL) {
        _userNameLBL = [[CYLabel alloc]initWithText:_userName size:14 textcolor:TEXT_BLACK_COLOR];
        [self addSubview:_userNameLBL];
        
        [_userNameLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_portraitIMG.mas_right).with.offset(AUTO(6));
            make.centerY.equalTo(_portraitIMG);
            make.size.mas_equalTo(_userNameLBL.bounds.size);
        }];
    }
    return _userNameLBL;
}

/*金额标题*/
- (CYLabel *)moneyTitleLBL{
    if (!_moneyTitleLBL) {
        _moneyTitleLBL = [[CYLabel alloc]initWithText:@"余额:" size:14 textcolor:TEXT_GRAY_COLOR];
        [self addSubview:_moneyTitleLBL];
        
        [_moneyTitleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_userNameLBL.mas_right).with.offset(40);
            make.centerY.equalTo(_userNameLBL);
            make.size.mas_equalTo(_moneyTitleLBL.bounds.size);
        }];
    }
    return _moneyLBL;
}

/*金额*/
- (CYLabel *)moneyLBL{
    if (!_moneyLBL) {
        _moneyLBL = [[CYLabel alloc]initWithText:[NSString stringWithFormat:@"%.3f",_money] size:14 textcolor:ColorHex(0xff5b05)];
        [self addSubview:_moneyLBL];
        
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_moneyTitleLBL.mas_right).with.offset(6);
            make.centerY.equalTo(_userNameLBL);
            make.size.mas_equalTo(_moneyLBL.bounds.size);
        }];
    }
    return _moneyLBL;
}

- (CYView *)bottomLine{
    if (!_bottomLine) {
        _bottomLine = [[CYView alloc]initWithColor:LINE_COLOR];
        [self addSubview:_bottomLine];
        
        [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 6));
            make.bottom.equalTo(self).with.offset(0);
        }];
    }
    return _bottomLine;
}

- (void)setImageName:(NSString *)imageName{
    if (_imageName != imageName) {
        _imageName = imageName;
        self.portraitIMG.hidden = NO;
    }
}

- (void)setUserName:(NSString *)userName{
    if (_userName != userName) {
        _userName = userName;
        self.userNameLBL.text = userName;
    }
}

- (void)setMoney:(float)money{
    if (_money != money){
        _money = money;
    self.moneyTitleLBL.hidden = NO;
    self.moneyLBL.text = [NSString stringWithFormat:@"%.3f",_money];
    [self setupSubViewLayout];
    }
}
- (void)setupSubViewLayout{
    
    [_userNameLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_userNameLBL.bounds.size);
    }];
    
    [_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_moneyLBL.bounds.size);
    }];
    
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
